package com.yc.autouser.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yc.autouser.entity.SysUser;
import com.yc.autouser.entity.vo.LoginUserVo;
import com.yc.autouser.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;
/**
 * @Classname UserDetailServiceImpl
 * @Description 登录密码验证
 * @Version 1.0.0
 * @Date 2022/7/26 23:16
 * @Created by Jiesen
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    SysUserMapper sysUserMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        QueryWrapper<SysUser> queryWrapper=new QueryWrapper();
        queryWrapper.eq("username",username);
        SysUser sysUser = sysUserMapper.selectOne(queryWrapper);
        if (Objects.isNull(sysUser)){
            throw new RuntimeException("用户密码错误");
        }
        return new LoginUserVo(sysUser);
    }
}
